<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Ping a server connection or reconnect if there is no connection</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.cubrid-ping" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_ping</h1>
  <p class="verinfo">(PECL CUBRID &gt;= 8.3.1)</p><p class="refpurpose"><span class="refname">cubrid_ping</span> &mdash; <span class="dc-title">Ping a server connection or reconnect if there is no connection</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-ping-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>cubrid_ping</strong></span>
    ([ <span class="methodparam"><span class="type">resource</span> <code class="parameter">$conn_identifier</code></span>
  ] ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Checks whether or not the connection to the server is working.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.cubrid-ping-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">conn_identifier</code></dt>

     <dd>

      <p class="para">
       The CUBRID connection identifier. If the connection identifier is not
       specified, the last connection opened by
       <span class="function"><a href="cubrid_connect.html" class="function">cubrid_connect()</a></span> is assumed.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.cubrid-ping-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> if the connection to the server CUBRID server is working, otherwise <strong><code>FALSE</code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-ping-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1174">
    <p><strong>Example #1 <span class="function"><strong>cubrid_ping()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />set_time_limit</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">33000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'demodb'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Assuming&nbsp;this&nbsp;query&nbsp;will&nbsp;take&nbsp;a&nbsp;long&nbsp;time&nbsp;*/<br /></span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"select&nbsp;*&nbsp;from&nbsp;athlete"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$result</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Query&nbsp;#1&nbsp;failed,&nbsp;exiting.'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #FF8000">/*&nbsp;Make&nbsp;sure&nbsp;the&nbsp;connection&nbsp;is&nbsp;still&nbsp;alive,&nbsp;if&nbsp;not,&nbsp;try&nbsp;to&nbsp;reconnect&nbsp;*/<br /></span><span style="color: #007700">if&nbsp;(!</span><span style="color: #0000BB">cubrid_ping</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Lost&nbsp;connection,&nbsp;exiting&nbsp;after&nbsp;query&nbsp;#1'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /></span><span style="color: #0000BB">cubrid_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;So&nbsp;the&nbsp;connection&nbsp;is&nbsp;still&nbsp;alive,&nbsp;let's&nbsp;run&nbsp;another&nbsp;query&nbsp;*/<br /></span><span style="color: #0000BB">$sql2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"select&nbsp;*&nbsp;from&nbsp;code"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$sql2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


</div></div></div></body></html>